function getToday() {
	var now = new Date();
	var year = now.getFullYear();
	var month = now.getMonth() + 1;
	var day = now.getDate();
	if (month < 10) {
		month = '0' + month;
	};
	if (day < 10) {
		day = '0' + day;
	};
	// 如果需要时分秒 
	// var h = now.getHours(); 
	// var m = now.getMinutes(); 
	// var s = now.getSeconds(); 
	var formatDate = year +'-' + month + '-' + day;
	return formatDate;
}

function getNowMonth() {
	var now = new Date();
	var year = now.getFullYear();
	var month = now.getMonth() + 1;
	if (month < 10) {
		month = '0' + month;
	};
	var formatMonth = year +'-' + month;
	return formatMonth;
}

// 是否为空
function isEmpty(obj) {
  if (typeof(obj) == "undefined" || (!obj && typeof(obj) != "undefined" && obj != 0)) {
    return true;
  }
  for (let i in obj) {
    return false;
  }
  return true;
}
// 提示错误信息
function showError(title) {
  var app = getApp();
  wx.showToast({
    title: title,
    icon: 'none',
    duration: 2000
  })
}

function showErrorPath(path, title) {
  var app = getApp();
  var url = path + 'images/icon-warn.png';
  wx.showToast({
    title: title,
    icon: 'none',
    // image: url,
    duration: 2000
  })
}



// 提示信息
function showStatus(title) {
  var app = getApp();
  wx.showToast({
    title: title,
    icon: 'none',
    duration: 3000
  })
}

// 加载中..
function showLoading(loading) {
  wx.showLoading({
    title: loading,
  })
}
// 取消加载中..
function hiddenLoading() {
  wx.hideLoading()
}

// 验证手机号
function validateMobile(mobile) {

  if (this.isEmpty(mobile)) {
    return false;
  }

  if (mobile.length == 0) {
    return false;
  }
  if (mobile.length != 11) {
    return false;
  }
  var reg = /^1[3|4|5|7|8][0-9]{9}$/;
  if (!reg.test(mobile)) {
    return false;
  }
  return true;
}

//验证邮箱
function validateEmail(email) {

  if (this.isEmpty(email)) {
    return false;
  }

  if (email.length == 0) {
    return false;
  }

  var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/;
  if (!reg.test(email)) {
    return false;
  }
  return true;
}

// 验证银行卡号
function checkBankNo(bankno) {
  var bankno = bankno.replace(/\s/g, '');

  if (bankno.length < 15 || bankno.length > 19) {
    return false;
  }
  var num = /^\d*$/;// 全数字
  if (!num.exec(bankno)) {
    return false;
  }
  // 开头两位
  var strBin = "10,12,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99";
  if (strBin.indexOf(bankno.substring(0, 2)) == -1) {
    return false;
  }
  // luhn校验
  //  if (!luhnCheck(bankno)) {
  //      return false;
  //  }
  return true;
}

//判断字符串是否为数字和字母组合
function checkRate(nubmer) {
  var re = /^[0-9a-zA-Z]*$/g; //判断正整数 /^[1-9]+[0-9]*]*$/    
  if (!re.test(nubmer)) {
    return false;
  } else {
    return true;
  }
}

//禁止连续点击
function buttonClicked(self) {
  self.setData({
    buttonClicked: true
  })
  setTimeout(function () {
    self.setData({
      buttonClicked: false
    })
  }, 1000)
}

module.exports = {
  isEmpty: isEmpty,
  showError: showError,
  hiddenLoading: hiddenLoading,
  showLoading: showLoading,
  validateMobile: validateMobile,
  showStatus: showStatus,
  showErrorPath: showErrorPath,
  checkRate: checkRate,
  validateEmail: validateEmail,
  checkBankNo: checkBankNo,
  buttonClicked:buttonClicked,
	getToday: getToday,
	getNowMonth: getNowMonth
}